package com.shenxuchen.crm.web.controller;

import com.shenxuchen.crm.constant.Constants;
import com.shenxuchen.crm.pojo.Clue;
import com.shenxuchen.crm.pojo.Transaction;
import com.shenxuchen.crm.pojo.User;
import com.shenxuchen.crm.service.ClueService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("clue")
public class ClueController {

    @Resource
    private ClueService clueService;

    @GetMapping("getList")
    public List getList(@RequestParam Map search) {
        return clueService.getList(search);
    }

    @GetMapping("getRefActs")
    public List getRefActs(String clueId) {
        return clueService.getRefActs(clueId);
    }

    @PostMapping("refActs")
    public Map refActs(String clueId, String[] actIds) {
        clueService.refActs(clueId, actIds);
        return Constants.RESP.SUC_MSG;
    }

    @DeleteMapping("unRef")
    public Map unRef(String clueId, String actId) {
        clueService.unRef(clueId, actId);
        return Constants.RESP.SUC_MSG;
    }

    @GetMapping("getById")
    public Clue getById(String id) {
        return clueService.getById(id);
    }

    @PostMapping("convert")
    public Map convert(String clueId, Boolean createTran, Transaction transaction, HttpSession session) {
        User user = (User) session.getAttribute(Constants.LOGIN_USER);
        clueService.convert(clueId, createTran, transaction, user);
        return Constants.RESP.SUC_MSG;
    }
}
